#include<bits/stdc++.h>
using namespace std;
int a[200010];
long long d1[100010][12][12], d0[2010][110][110];
int n;
bool P;
inline long long& getD(int& X, int& Y, int& Z) {
    if (P) {
        return d1[X][Y][Z];
    } else {
        return d0[X][Y][Z];
    }
}
long long f(int x, int r, int b) {
    if (x >= n) {
        return 0;
    }
    long long& d = getD(x, r, b), & rd = getD(x, b, r), res = 0;
    if (d > -1 || rd > -1) {
        res = max(d, rd);
        d = res;
        rd = res;
    } else {
        int ax = a[x];
        res = f(x + 1, ax, b);
        if (ax == r) {
            res += ax;
        }
        if (ax == b) {
            res = max(res, f(x + 1, r, ax) + ax);
        } else {
            res = max(res, f(x + 1, r, ax));
        }
        d = res;
        rd = res;
    }
    return d;
}
int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T;
    cin >> T;
    while (T--) {
        cin >> n;
        if (n > 2000) {
            P = 1;
            memset(d1, 0xffff, sizeof(d1));
        } else {
            P = 0;
            memset(d0, 0xffff, sizeof(d0));
        }
        for (int i = 0; i < n; ++i) {
            scanf("%d", a + i);
        }
        printf("%lld\n", f(0, 0, 0));
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}